'use strict';
module.exports = {
  up: (queryInterface, Sequelize) => {
    return queryInterface.createTable('Goods', {
      id: {
        allowNull: false,
        autoIncrement: true,
        primaryKey: true,
        type: Sequelize.INTEGER
      },
      number: {
        allowNull: false,
        type: Sequelize.INTEGER(3),
        defaultValue: 0
      },
      style: {
        allowNull: false,
        type: Sequelize.INTEGER(1)
      },
      status: {
        allowNull: false,
        type: Sequelize.INTEGER(1),
        defaultValue: 0
      },
      type: {
        allowNull: false,
        type: Sequelize.INTEGER(1),
        defaultValue: 0
      },
      nickname: {
        allowNull: false,
        type: Sequelize.STRING(255)
      },
      brief: {
        allowNull: false,
        type: Sequelize.STRING(255)
      },
      remark: {
        allowNull: false,
        type: Sequelize.STRING(255),
        defaultValue: ''
      },
      userId: {
        allowNull: false,
        type: Sequelize.INTEGER
      },
      sponsor: {
        allowNull: false,
        type: Sequelize.STRING(255),
        defaultValue: ''
      },
      pv: {
        allowNull: false,
        type: Sequelize.INTEGER(1),
        get() { return this.app.redis.get('goods').get(`goodsUsers_pv_${this.getDataValue('id')}`) || 0 }
      },
      uv: {
        allowNull: false,
        type: Sequelize.INTEGER(1),
        get() { return this.app.redis.get('goods').get(`goodsUsers_uv_${this.getDataValue('id')}`) || 0 }
      },
      appId: {
        allowNull: false,
        type: Sequelize.STRING(100),
        defaultValue: ''
      },
      endAt: {
        type: Sequelize.DATE,
      },
      createdAt: {
        allowNull: true,
        type: Sequelize.DATE,
      },
      updatedAt: {
        allowNull: true,
        type: Sequelize.DATE,
      },
      deletedAt: {
        type: Sequelize.DATE,
      }
    }, {
      charset: 'utf8mb4',
      collate: 'utf8mb4_general_ci',
      comment: '商品表',
      indexes: [{
        fields: ['type']
      }, {
        fields: ['status']
      }],
    });
  },
  down: (queryInterface, Sequelize) => {
    return queryInterface.dropTable('Goods');
  }
};